package com.party.core.service.sign.biz;

import com.google.common.collect.Maps;
import com.party.common.utils.DateUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * Created by yifeng
 *
 * @date 2018/3/9 0009
 * @time 下午 17:28
 */
@Service
public class SignBusinessBizService {
    /**
     * 拼接日期查询参数
     *
     * @param type 类型 0：今天 1：本周 2：本月 3：历史（所有） 4：昨天
     * @return
     */
    public Map<String, Object> appendSearchParams(Integer type) {
        if (type == null) {
            type = 0;
        }
        //按时间段查
        String startTime = null;
        String endTime = null;
        if (null != type) {
            String today = DateUtils.getTodayStr();

            //今天
            if (0 == type) {
                startTime = today;
                endTime = today;
            }
            //本周
            else if (1 == type) {
                startTime = DateUtils.formatDateTime(DateUtils.getFirstDayOfWeek(0));
                endTime = today;
            }
            //本月
            else if (2 == type) {
                startTime = DateUtils.formatDateTime(DateUtils.getFirstDayOfMonth(0));
                endTime = today;
            }
            //历史
            else if (3 == type) {
                // endTime = DateUtils.formatDateTime(DateUtils.getLastDayOfMonth(-1));
                startTime = null;
                endTime = null;
            } else if (4 == type) {
                Date yesterdayDate = DateUtils.addDay(new Date(), -1);
                String yesterday = DateUtils.formatDate(yesterdayDate, DateUtils.DATETIME_PATTERN);
                startTime = yesterday;
                endTime = yesterday;
            }
        }
        Map<String, Object> params = Maps.newHashMap();
        params.put("startTime", startTime);
        params.put("endTime", endTime);
        return params;
    }
}
